<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<title></title>
</h:head>

<h:body>

	<ui:composition template="/webApp/layout/template.xhtml">
		<ui:define name="conteudo">

			<h:form prependId="false">
				<p:growl id="messages" globalOnly="false" showDetail="false"
					sticky="false" life="3000" />
				<h:panelGrid>
					<h:panelGrid columns="2">
						<f:facet name="header">
							<p:outputLabel value="Cadastro de Pedido" />
						</f:facet>
					</h:panelGrid>

					<h:panelGrid id="grid2" style="display:block" columns="2">
						<h:panelGrid id="grid" style="display:block" columns="2">
							<p:outputLabel value="Nome Cliente:" />
							<p:outputLabel value="#{pedidoBean.cliente.nome}" />

							<p:outputLabel for="data" value="Data de Entrega:" />
							<p:calendar id="data" value="#{pedidoBean.pedido.dataEntrega}"
								effect="fold" required="true"
								requiredMessage="Campo Data de Entrega é obrigatório" />
						</h:panelGrid>

						<p:commandButton value="Adicionar Item" type="button"
							onclick="PF('dlg1').show();" />

						<h:panelGrid id="painel" columns="2"
							rendered="#{not empty pedidoBean.pedido.itensPedido}">
							<p:dataTable value="#{pedidoBean.pedido.itensPedido}" var="item">
								<p:column>
									<f:facet name="header">
										<p:outputLabel value="Descrição" />
									</f:facet>
									<p:outputLabel value="#{item.descricao}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<p:outputLabel value="Quantidade" />
									</f:facet>
									<p:outputLabel value="#{item.qtde}" />
								</p:column>

								<p:column>
									<f:facet name="header">
										<p:outputLabel value="Valor" />
									</f:facet>
									<p:outputLabel value="R$ #{item.valor}" />
								</p:column>

								<p:columnGroup type="footer">
									<p:row>
										<p:column colspan="2" footerText="Total Pedido: " style="text-align:right" />
										<p:column footerText="#{pedidoBean.pedido.valorPedido}" />
									</p:row>
								</p:columnGroup>

							</p:dataTable>
						</h:panelGrid>

						<p:dialog header="Adicionar Item" widgetVar="dlg1" minHeight="40">
							<h:panelGrid columns="2">
								<p:outputLabel value="Descrição: " />
								<p:inputText value="#{pedidoBean.item.descricao}" />

								<p:outputLabel value="Quantidade: " />
								<p:inputText value="#{pedidoBean.item.qtde}" required="true"
									requiredMessage="Campo Quantidade obrigatório">
								</p:inputText>

								<p:outputLabel value="Valor: " />
								<p:inputText value="#{pedidoBean.item.valor}" required="true"
									requiredMessage="Campo Valor obrigatório">
									<f:convertNumber type="currency" />
								</p:inputText>

								<h:commandButton actionListener="#{pedidoBean.adicionarItem}"
									value="Adicionar" update="painel" />
							</h:panelGrid>
						</p:dialog>

					</h:panelGrid>
				</h:panelGrid>

				<p:commandButton value="Cadastrar"
					action="#{pedidoBean.cadastrarPedido}" update="messages" />
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>



</html>